package player.ui.dialog;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import player.PS;
import player.mplayer.MediaInfo;
import player.ui.playlist.PlayListModel;


import net.miginfocom.swing.MigLayout;

public class MyTableCellRenderer2 implements TableCellRenderer{

	Component com=null;
	PlayListModel pm=null;	
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		JPanel p=new JPanel();
		com=p;
		if(isSelected){
			p.setLayout(new MigLayout("inset 13 0 0 0 "));
		}else{
			p.setLayout(new MigLayout("inset -2 0 0 0 "));
		}

		pm=(PlayListModel) table.getModel();
		MediaInfo mf=(MediaInfo) pm.getValueAt(row, 0);

		JLabel l=null;
		if(mf!=null){
			String s1=getTimeString(mf.length);
			String s2=getSizeString(mf.fileSize);
			l=new JLabel(s1+" "+s2);
			p.add(l,"");
		}
		
		if(row%2 == 0) 
			com.setBackground(new Color(240,251,254));
		else if(row%2 == 1) 
			com.setBackground(new Color(230,231,254));
		return p;
	}


	String getSizeString(long size){
		int gb=(int) (size/(1024*1024*1024));
		int gbl=(int) (size%(1024*1024*1024));
		int mb=gbl/(1024*1024);
		int mbl=gbl%(1024*1024);
		int kb=mbl/(1024);
		String ls="";
		if(gb>0){
			ls+=gb+",";
		}
		if(mb>0){
			String mbs="";
			if(gb>0){
				if(mb<10){
					mbs+="00";
				}else if(mb<100){
					mbs+="0";
				}
			}
			mbs+=mb;
			ls+=mbs+",";
		}
		
		if(kb>0){
			String kbs="";
			if(gb>0){
				if(kb<10){
					kbs+="00";
				}else if(kb<100){
					kbs+="0";
				}
			}
			kbs+=kb;
			ls+=kbs+"KB";
		}
		return ls;
	}

	public static String getTimeString(int playOffset){
		int ds = playOffset;
		int d0 = ds / 3600;
		int d1 = Math.abs(d0 * 60 - ds / 60);
		int d2 = ds % 60;
		StringBuffer str2 = new StringBuffer();

		if (d0 < 10) {
			str2.append(0);
		}
		str2.append(d0);
		str2.append(":");
		if (d1 < 10) {
			str2.append(0);
		}
		str2.append(d1);
		str2.append(":");
		if (d2 < 10) {
			str2.append(0);
		}
		str2.append(d2);

		if (ds > 0) {
			//	ToolBar1.time_label.setVisible(true);
		}
		return str2.toString();
	}

}

class JLabel2 extends JLabel{
	private static final long serialVersionUID = 1L;
	String s1;String s2;
	JLabel2(String s1,String s2){
		this.s1=this.s2;
	}
	 public void paint(Graphics g){
		Graphics2D g2d=(Graphics2D)g;
		g2d.setColor(java.awt.Color.BLUE);
		g2d.fillRect(0, 0, 20, 20);
		g2d.drawString(s1, 0, 15);
		g2d.drawString(s2, 60, 15);
	}
}
